﻿Imports System.Data.SqlClient

Public Class clsProductos
    Private mintIdProducto As Integer
    Private mstrCodigoProducto As String
    Private mstrNombre As String
    Private mstrNombreMecanico As String
    Private mstrNombreProveedor As String
    Private mstrNombreLargo As String
    Private mstrDescripcion As String
    Private mintStatus As Integer
    Private mstrFamilia As String
    Private mstrSubFamilia As String
    Public Property IdProducto() As Integer
        Get
            Return mintIdProducto
        End Get
        Set(ByVal value As Integer)
            mintIdProducto = value
        End Set
    End Property
    Public Property CodigoProducto() As String
        Get
            Return mstrCodigoProducto
        End Get
        Set(value As String)
            mstrCodigoProducto = value
        End Set
    End Property
    Public Property Nombre() As String
        Get
            Return mstrNombre
        End Get
        Set(ByVal value As String)
            mstrNombre = value
        End Set
    End Property
    Public Property NombreMecanico() As String
        Get
            Return mstrNombreMecanico
        End Get
        Set(ByVal value As String)
            mstrNombreMecanico = value
        End Set
    End Property
    Public Property NombreProveedor() As String
        Get
            Return mstrNombreProveedor
        End Get
        Set(ByVal value As String)
            mstrNombreProveedor = value
        End Set
    End Property
    Public Property NombreLargo() As String
        Get
            Return mstrNombreLargo
        End Get
        Set(ByVal value As String)
            mstrNombreLargo = value
        End Set
    End Property
    Public Property Descripcion() As String
        Get
            Return mstrDescripcion
        End Get
        Set(ByVal value As String)
            mstrDescripcion = value
        End Set
    End Property
    Public Property Status() As Integer
        Get
            Return mintStatus
        End Get
        Set(ByVal value As Integer)
            mintStatus = value
        End Set
    End Property
    Public Property Familia() As String
        Get
            Return mstrFamilia
        End Get
        Set(value As String)
            mstrFamilia = value
        End Set
    End Property
    Public Property SubFamilia() As String
        Get
            Return mstrSubFamilia
        End Get
        Set(ByVal value As String)
            mstrSubFamilia = value
        End Set
    End Property

    Public Sub New()
        mintIdProducto = 0
        mstrCodigoProducto = ""
        mstrNombre = ""
        mstrNombreMecanico = ""
        mstrNombreProveedor = ""
        mstrNombreLargo = ""
        mstrDescripcion = ""
        mintStatus = 0
        mstrFamilia = ""
        mstrSubFamilia = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Productos (" & _
                            "CodigoProducto," & _
                            "Nombre," & _
                            "NombreMecanico," & _
                            "NombreProveedor," & _
                            "NombreLargo," & _
                            "Descripcion," & _
                            "Status," & _
                            "Familia," & _
                            "SubFamilia) " & _
                            "VALUES (" & _
                            "substring(@CodigoProducto,1,50)," & _
                            "substring(@Nombre,1,200)," & _
                            "substring(@NombreMecanico,1,200)," & _
                            "substring(@NombreProveedor,1,200)," & _
                            "substring(@NombreLargo,1,300)," & _
                            "substring(@Descripcion,1,500)," & _
                            "@Status," & _
                            "substring(@Familia,1,100)," & _
                            "substring(@SubFamilia,1,100)) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CodigoProducto", mstrCodigoProducto)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("NombreMecanico", mstrNombreMecanico)
        Command.Parameters.AddWithValue("NombreProveedor", mstrNombreProveedor)
        Command.Parameters.AddWithValue("NombreLargo", mstrNombreLargo)
        Command.Parameters.AddWithValue("Descripcion", mstrDescripcion)
        Command.Parameters.AddWithValue("Status", mintStatus)
        Command.Parameters.AddWithValue("Familia", mstrFamilia)
        Command.Parameters.AddWithValue("SubFamilia", mstrSubFamilia)
        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el producto ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Public Sub Actualizar()

        Dim strSqlQry As String
        Dim cnConn As New SqlConnection

        cnConn.ConnectionString = CitraConnection
        strSqlQry = "Update Productos Set " & _
                    "Nombre=substring(@Nombre,1,200)," & _
                    "NombreMecanico=substring(@NombreMecanico,1,200)," & _
                    "NombreProveedor=substring(@NombreProveedor,1,200)," & _
                    "NombreLargo=substring(@NombreLargo,1,300)," & _
                    "Descripcion=substring(@Descripcion,1,500)," & _
                    "Status=@Status," & _
                    "Familia=substring(@Familia,1,100)," & _
                    "SubFamilia=substring(@SubFamilia,1,100) " & _
                    "Where CodigoProducto=@CodigoProducto"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("CodigoProducto", mstrCodigoProducto)
        Command.Parameters.AddWithValue("Nombre", mstrNombre)
        Command.Parameters.AddWithValue("NombreMecanico", mstrNombreMecanico)
        Command.Parameters.AddWithValue("NombreProveedor", mstrNombreProveedor)
        Command.Parameters.AddWithValue("NombreLargo", mstrNombreLargo)
        Command.Parameters.AddWithValue("Descripcion", mstrDescripcion)
        Command.Parameters.AddWithValue("Status", mintStatus)
        Command.Parameters.AddWithValue("Familia", mstrFamilia)
        Command.Parameters.AddWithValue("SubFamilia", mstrSubFamilia)
        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el liquidación ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
